﻿using System;
using System.IO;

namespace WorldIndex.MDGImport
{
    class Program
    {
        static void Main(string[] args)
        {
            bool done = false;
            do
            {
                Console.WriteLine("Select one of the following operations:");
                Console.WriteLine("\t1 -- Import external MDGS dataset from UN and install to SQL database.");
                Console.WriteLine("\t2 -- Import local test file MDGS dataset to SQL database.");
                Console.WriteLine("\t3 -- Same as nr. 2 but to local file.");
                Console.Write("Enter Your selection (0 to exit): ");
                string strSelection = Console.ReadLine();
                int iSel;

                try
                {
                    iSel = int.Parse(strSelection);
                }
                catch (FormatException)
                {
                    Console.WriteLine("\r\nWhat?\r\n");
                    continue;
                }

                Console.WriteLine("You selected  " + iSel);
                switch (iSel)
                {
                    case 0:
                        done = true;
                        break;
                    case 1:
                        InstallExternalMdgDataset();
                        break;
                    case 2:
                        InstallInternalTestMdgDataset();
                        break;
                    case 3:
                        InstallInternalTestMdgDatasetToFile();
                        break;
                    default:
                        Console.WriteLine("You selected an invalid number: {0}\r\n", iSel);
                        continue;
                }

                Console.WriteLine();
            } 
            while (!done);

            Console.WriteLine("\nGoodbye!");
        }

        public static void InstallExternalMdgDataset()
        {
            var mdgImport = new MdgImport();
            mdgImport.DownloadAndInstallMdgDataset();
        }

        public static void InstallInternalTestMdgDataset()
        {
            var mdgImport = new MdgImport();
            mdgImport.InstallMdgDataIntoDatabase(new FileInfo(Properties.Resources.MdgTestFilePath));
        }

        public static void InstallInternalTestMdgDatasetToFile()
        {
            var mdgImport = new MdgImport();
            mdgImport.InstallMdgDataIntoFile(new FileInfo(Properties.Resources.MdgTestFilePath));
        }
    }
}
